package com.bird.thread.base.uncaughtexception;

import java.util.concurrent.TimeUnit;

/**
 * @author sijunqiang
 * @data 2021/7/3 15:15
 * @description: 验证：使用自己定义的未捕获的异常类处理子线程抛出的异常。
 */
public class UseOwnUncaughtExceptionHandler implements Runnable {
    public static void main(String[] args) throws InterruptedException {

        // 为当前线程设置一个未捕获异常器。专门捕获那些导致线程终止的未捕获异常。
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandle("捕获器-1"));

        new Thread(new UseOwnUncaughtExceptionHandler(), "thread-1").start();
        TimeUnit.SECONDS.sleep(1);

        new Thread(new UseOwnUncaughtExceptionHandler(), "thread-2").start();
        TimeUnit.SECONDS.sleep(2);

        new Thread(new UseOwnUncaughtExceptionHandler(), "thread-3").start();
        TimeUnit.SECONDS.sleep(3);

        new Thread(new UseOwnUncaughtExceptionHandler(), "thread-4").start();
        TimeUnit.SECONDS.sleep(4);

        int a = 1 / 0;
    }

    @Override
    public void run() {
        throw new RuntimeException();
    }
}
